package com.css.msgcenter.admin.msglog.service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.msgcenter.server.QueryMsg;
import com.css.msgcenter.server.model.MsgApp;

public class MsgLogService {
	private static Log log = LogFactory.getLog(MsgLogService.class);
	
	public static List getSelect4App() {
		List lst = QueryMsg.idToObj(MsgApp.class, new QueryMsg("select a.uuid from MsgApp a").list());
		MsgApp o = new MsgApp();
		o.setAppName("全部");
		lst.add(o);
		return lst;
	}
	
	public static String getAppName(String appId) {
		MsgApp o = QueryMsg.get(MsgApp.class, appId);
		if(o != null)
			return o.getAppName();
		else 
			return "";
	}
	
	public static String getString4Month(Date bt){
		if(bt==null)
			return "";
		StringBuilder sb = new StringBuilder();
		Calendar cal = new GregorianCalendar(); 
		cal.setTime(bt);
		final int DATEN = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		for(int i=0; i<DATEN; i++) {
			sb.append((i==0?"":",")+"'"+sdf.format(cal.getTime())+"'");
			cal.add(cal.DAY_OF_MONTH, 1);
		}
		return sb.toString();
	}
	
	public static String toStringFunc(HashMap map, Date bt){
		if(map == null
				|| bt==null)
			return "";
		StringBuilder sb = new StringBuilder();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = new GregorianCalendar(); 
		cal.setTime(bt);
		final int DATEN = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		for(int i=0; i<DATEN; i++) {
			Integer v = (Integer) map.get(sdf.format(cal.getTime()));
			if(v!=null)
				sb.append((i==0?"":",")+v);
			else
				sb.append((i==0?"":",")+0);
			cal.add(Calendar.DAY_OF_MONTH, 1);
		}
		return sb.toString();
		
	}
}
